(function() {
    'use strict';

    /**
     * @ngdoc directive
     * @name webApp.directive:buyerlist
     * @description
     * # buyerlist 

    用法：
    <buyerlist ng-model="stockIn.warehouse_user_id"></buyerlist>

     */
    angular.module('webApp')
        //调用其他方法
        .run(["$templateCache", "dataService", function($templateCache, dataService) {
            var tplName = "views/directives.buyerlist.html";
            dataService.tpl(tplName).then(function(html) {
                $templateCache.put(tplName, html);
            });
        }])
        .directive('buyerlist', ['dataService', '$compile', function(dataService, $compile) {
            return {
                restrict: 'E',
                // require: 'ngModel',
                replace: true,
                scope: {
                    orderId: '=',
                    order:"=",
                },
                template: "<span><a href='javascript:void(0);'   ng-click='showPop();'>{{order.deliver_name || ngModel}}</span>",
                controller: ['$templateCache', '$rootScope', '$scope', '$timeout', function($templateCache, $rootScope, $scope, $timeout) {

                    $scope.showPop = function() {
                        $.alert({
                            backdrop: 'static',
                            keyboard: true,
                            title: '<form class="sui-form" style="margin:0px;"><span>{{"Receiving information"|translate}}</span></form>',
                            body: $templateCache.get("views/directives.buyerlist.html"),
                            okBtn: '{{"ok"|translate}}',
                            closeBtn: true,
                            transition: true,
                            width: 'large',
                            height: '200',
                            show: function(e) {
                                $compile($(e.currentTarget).contents())($scope);
                                return true;
                            },
                            okHide: function(e) {

                            },
                        });
                    }
                    $scope.pageData = function() {
                        if($scope.order){
                            return ;
                        }
                        return dataService.orderOne($scope.orderId).then(function(data) {
                            $scope.order = data;
                        });
                    }

                    $scope.pageData();
                }]
            }
        }])
        .run(["$templateCache", "dataService", function($templateCache, dataService) {
            var tplName = "views/directives.activityget.html";
            dataService.tpl(tplName).then(function(html) {
                $templateCache.put(tplName, html);
            });
        }])
        .directive('activityget', ['dataService', '$compile', function(dataService, $compile) {
            return {
                restrict: 'E',
                // require: 'ngModel',
                replace: true,
                scope: {
                    // orderId: '=',
                    bargainId: '=',
                },
                template: "<span><a href='javascript:void(0);'   ng-click='showPop();'class='sui-btn btn-success'>统计</span>",
                controller: ['$templateCache', '$rootScope', '$scope', '$timeout', function($templateCache, $rootScope, $scope, $timeout) {

                    $scope.showPop = function() {
                        $.alert({
                            backdrop: 'static',
                            keyboard: true,
                            title: '<form class="sui-form" style="margin:0px;"><span>{{"Receiving information"|translate}}</span></form>',
                            body: $templateCache.get("views/directives.activityget.html"),
                            // okBtn: '{{"ok"|translate}}',
                            closeBtn: true,
                            transition: true,
                            width: 'large',
                            height: '200',
                            hasfoot: false,
                            show: function(e) {
                                $compile($(e.currentTarget).contents())($scope);
                                return true;
                            },
                            okHide: function(e) {

                            },
                        });
                    }

                    $scope.pageData = function(pageNo) {
                        var data = { query: { bargain_rule_id: $scope.bargainId } }
                        return dataService.activityget(data).then(function(data) {
                            $scope.orders = data.bargain_activitys[0];
                            // console.log("orders", $scope.orders);
                        });
                    }

                    $scope.pageData();
                }],
                link: function(scope, element, attrs, ctrl) {

                }
            }
        }]);
})();